package com.atguigu.yygh.msm.controller;

import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.msm.service.MsmService;
import com.atguigu.yygh.msm.utils.SDKTestSendTemplateSMS;
import com.atguigu.yygh.vo.msm.MsmVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.concurrent.TimeUnit;

/**
 * ClassName: MsmApiController
 * Package: com.atguigu.yygh.msm.controller
 *
 * @Date: 2021/8/23 15:24
 * @author: 浪漫
 * @Description:
 */
@RestController
@RequestMapping("/api/msm")
public class MsmApiController {



    @Autowired
    private MsmService msmService;


    @GetMapping("send/{phone}")
    public Result sendCode(@PathVariable String phone) {
        //HashMap<String, Object> result = SDKTestSendTemplateSMS.sms(phone);
        //从redis获取验证码，如果获取获取到，返回ok
        // key 手机号  value 验证码
        //String code = redisTemplate.opsForValue().get(phone);

        MsmVo msmVo = new MsmVo();
        msmVo.setPhone(phone);


        if(msmService.send(msmVo)) {
            return Result.ok().message("发送短信成功！");
        }
            return Result.fail().message("发送短信失败");
       }


}
